#
# @lc app=leetcode.cn id=474 lang=python
#
# [474] 一和零
#

# @lc code=start
class Solution(object):
    def findMaxForm(self, strs, m, n):
        """
        :type strs: List[str]
        :type m: int
        :type n: int
        :rtype: int
        """
        dp = [[0]*(n+1) for _ in range(m+1)]

        for str_i in strs:
            num0 = str_i.count('0')
            num1 = str_i.count('1')
            if num0>m or num1>n:
                continue
            for i in range(m, num0-1, -1):
                for j in range(n, num1-1, -1):
                    dp[i][j] = max(dp[i][j], 1+dp[i-num0][j-num1])
        return dp[-1][-1]


        
        
# @lc code=end

